package com.example.demo.controller;

import ch.qos.logback.core.util.StringUtil;
import jakarta.servlet.http.HttpSession;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/calc")
public class CalcController {
    @RequestMapping("/param")
    public  Boolean transferParam(Integer num1, Integer num2, HttpSession session){
        //参数校验
        if(num1==null||num2==null){
            return false;
        }
        session.setAttribute("num1",num1);
        session.setAttribute("num2",num2);
        return true;
    }

    @RequestMapping(value = "/getParam",produces = "application/json")
    public String getParam(HttpSession session){
        Integer num1=(Integer)session.getAttribute("num1");
        Integer num2=(Integer)session.getAttribute("num2");
        return "{\"num1\":"+num1+",\"num2\":"+num2+"}";
    }

    @RequestMapping("/sum")
    public Integer sum(Integer num1,Integer num2){
        Integer sum=num1+num2;
        return sum;
    }

}
